# Makefile
# ----------------------------------------------
# Author : Woo-Hyun Kim
# E-mail : woorung@nhncorp.com or woorung@gmail.com
# Date : Nov. 7, 2008

# profile
include ../../../etc/profile.mk

# coord
wooh_slib = /home/woorung/wn/lib/.libs/wooh
coord_slib = /home/woorung/wn/lib/.libs/coord
coord_inc = -I/home/woorung/wn/include

# others
other_lib = -lpthread -lmagic -lz -ldl

srcs = $(wildcard x*.cpp)

# python
python_inc = -I/usr/include/python2.3 -I/usr/lib/python2.3/config
python_lib = 

# php
php_inc = `php-config --includes`
php_lib = `php-config --libs`

# java
java_inc = -I/usr/lib/gcc/i386-redhat-linux/3.4.3/include/java
#java_inc = -I/usr/lib/gcc/x86_64-redhat-linux/3.4.3/include/java
java_lib = 

# swig
SWIG=$(WNXL)/swig/bin/swig
swig_modules = $(srcs:x%.cpp=x%)
#swig_lang = python
swig_lang = php5
#swig_lang = java
#swig_incs = $(python_inc)
#swig_libs = $(pythonp_lib)
swig_incs = $(php_inc)
swig_libs = $(php_lib)
#swig_incs = $(java_inc)
#swig_libs = $(java_lib)



ifeq ($(swig_lang), java)
	make_requisite_classes = cd ./.${swig_lang} && javac ../example.java
endif



all: ready_for_swig $(swig_modules)

ready_for_swig :
	mkdir -p ./.${swig_lang}/

$(swig_modules) : %: %.h
	cp $*.cpp $*.h ./.${swig_lang}/
	cd ./.${swig_lang}/ && $(SWIG) $(swig_defs) -o $*_$(swig_lang).cpp -c++ -$(swig_lang) $<
	cd ./.${swig_lang}/ && g++ -c $*.cpp $*_$(swig_lang).cpp $(swig_incs) -I$(WNI) -fPIC
	cd ./.${swig_lang}/ && g++ -shared $*.o $*_$(swig_lang).o ${wooh_slib}/*.o ${coord_slib}/*.o -o _$*.so -I${coord_inc} ${other_lib} -fPIC
	${make_requisite_classes}


install : install_${swig_lang}

install_${swig_lang} :
	mkdir -p ${WNL}/.${swig_lang}/
	cp -rf ./.${swig_lang}/*.so ${WNL}/.${swig_lang}/
	-cp -rf ./.${swig_lang}/*.php ${WNL}/.${swig_lang}/
	-cp -rf ./.${swig_lang}/*.py ${WNL}/.${swig_lang}/
	-cp -rf ./.${swig_lang}/xCoord.class ${WNL}/.${swig_lang}/
	-cp -rf ./.${swig_lang}/xcoordJNI.class ${WNL}/.${swig_lang}/
	cp -rf example.php ../example/
	cp -rf example.py ../example/
	cp -rf example.java ../example/

uninstall :
	rm -rf ${WNL}/.${swig_lang}/*


clean :
	rm -rf ./.${swig_lang}/*
